import router, { varRouter, constantRoutes } from '@/router'
const state = {
  routes: [],
  points: {
    pointUserUpdate: 'point-user-update',
    pointUserDelete: 'point-user-delete',
    pointUserLeave: 'point-user-leave',
    pointUserSetJob: 'point-user-setjob',
    // 权限页面的权限标识
    pointPermissionAdd: 'point-permission-add',
    pointPermissionDelete: 'point-permission-delete'
  }
}

const mutations = {
  filterRouter(state, roles) {
    // 筛选路由
    const filterRouter = varRouter.filter(item =>
      roles.menus.includes(item.name)
    )
    // 把404放到最后
    const router404 = { path: '*', redirect: '/404', hidden: true }
    // 将筛选后的路由规则放到动态路由内
    router.addRoutes([...filterRouter, router404])
    // 保存最终的路由规则
    state.routes = [...constantRoutes, ...filterRouter, router404]
  }
}

const actions = {}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
